<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="../vue.js"></script>
</head>

<body>
    <div id="app">
        <form>
            <div class="form-group">
                <label for="name">姓名</label>
                <input v-model='info.name' type="text" class="form-control" id="name" placeholder="姓名">
            </div>
            <div class="form-group">
                <label for="phone">手机号</label>
                <input v-model="info.phone" type="text" class="form-control" id="phone" placeholder="手机号">
            </div>
            <div class="form-group">
                <label for="remark">备注</label>
                <input v-model='info.remark' type="text" class="form-control" id="remark" placeholder="备注">
            </div>

            <button type="button" class="btn btn-default" @click='add'>添加</button>
            <button type="button" class="btn btn-default">重置</button>
        </form>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>姓名</th>
                    <th>手机号</th>
                    <th>备注</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for='(item,index) in studenList' :key="index">
                    <td>{{item.name}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.remark}}</td>
                    <td><button @click='remove(index)'>删除</button></td>
                </tr>
                <tr>
                    <td v-if="studenList==0" colspan="4">暂无数据</td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
<script>
    let vm = new Vue({
        el: '#app',
        data: {
            info: {
                name: '',
                phone: '',
                remark: ''
            },
            studenList: JSON.parse(localStorage.getItem('studenList'))||[]
        },
        methods: {
            add() {
                this.studenList.push(this.info)
                localStorage.setItem('studenList',JSON.stringify(this.studenList))
               this.resict()
            },
            resict(){
                this.info = {
                    name: '',
                    phone: '',
                    remark: ''
                }
            },
            remove(index){
                this.studenList.splice(index,1)
                localStorage.setItem('studenList',JSON.stringify(this.studenList))

            }
        }
    })
</script>

</html>